#include <stdio.h>
#include <QSqlDatabase>
#include <QObject>
#include "cssettingsinformation.h"
#include "comresponse.h"
#include "protoolsstandard.h"
#include "user.h"
#include <QList>

#ifndef DATABASEFACADE_H
#define DATABASEFACADE_H

class DataBaseFacade : QObject
{
public:
    DataBaseFacade();

    ~DataBaseFacade();

    // This is to test the connection when we change the path of the database.
    bool TestConnection(ComResponse *resp);

    // This is to open our connection.
    bool OpenConnection(QSqlDatabase &qd);

    // This is to close our connection.
    bool CloseConnection(QSqlDatabase &qd);

    // This is going to delete the tickets and other stuff.
    bool UpdateProductionByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // SELECT Production_ProductionID, VenueName,VenueAddress1,VenueAddress2,VenueAddress3,VenueCity,VenueState,VenuePostalCode,VenueSpecialNotes FROM Venues WHERE Production_ProductionID = ?
    bool SelectVenuesByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // select Cost, NumberAvailable, Production_ProductionID, TierDescription, TierName from Tickets where Production_ProductionID = ?
    bool SelectTicketsByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // select TaxName, TaxRate, Production_ProductionID from Taxes where Production_ProductionID = ?";
    bool SelectTaxesByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // SELECT Main_lblSize ,Main_lblVenues ,Main_lblArtists ,Main_lblPerformaceDates ,Main_lblProdCost ,Main_lblStaffCost ,Main_lblAdminCosts ,Main_lblMktgCosts ,Main_lblSecCosts ,Main_lblOpsCost ,Main_lblSubTotal ,Main_TicketCount ,Main_lblTicketSalesPos ,Main_lblPossibleDollars ,Main_lblPossibleTicletCOmm ,Main_lblTax ,Main_lblNet ,AdminScreen_AdminStaff ,AdminScreen_BoxOffStaff ,AdminScreen_TicketTakers ,AdminScreen_TrafficControl ,AdminScreen_OfficeCosts ,AdminScreen_OfficeEquipment ,AdminScreen_Postage ,AdminScreen_Phones ,AdminScreen_LegalAccountant ,AdminScreen_RentPower ,AdminScreen_Insurance ,AdminScreen_Permits ,AdminScreen_ASCAP ,AdminScreen_Ticketprinting ,MarketingScreen_PublicRelations ,MarketingScreen_CreativePrinting ,MarketingScreen_MktgStaff ,OperationsScreen_SiteOpsCoordinator ,OperationsScreen_Laborers ,OperationsScreen_VenueCost ,OperationsScreen_LandRestore ,OperationsScreen_Kamode ,OperationsScreen_WaterTrucks ,OperationsScreen_EquipmentRent ,OperationsScreen_Petroleum ,OperationsScreen_PowerGenerator ,OperationsScreen_PerimeterLights ,OperationsScreen_Fence ,OperationsScreen_OpsVehicles ,OperationsScreen_ShuttleBuses ,OperationsScreen_MotorHomes ,OperationsScreen_LandPrep ,ProductionScreen_Talent ,ProductionScreen_Sound ,ProductionScreen_Lights ,ProductionScreen_Catering ,ProductionScreen_Stage ,ProductionScreen_LightTowers ,ProductionScreen_Aerials ,SecurityScreen_SecStaff ,SecurityScreen_Vehicles ,SecurityScreen_FirstAid ,SecurityScreen_Communications ,SecurityScreen_Ids ,StaffScreen_ProdStaff ,StaffScreen_StageHands ,TicketComm ,ProductionName,ProductionID FROM Productions WHERE ProductionName = ?
    bool SelectProductionByName(ProtoolsStandard *pto, ComResponse *resp);

    // SELECT Main_lblSize ,Main_lblVenues ,Main_lblArtists ,Main_lblPerformaceDates ,Main_lblProdCost ,Main_lblStaffCost ,Main_lblAdminCosts ,Main_lblMktgCosts ,Main_lblSecCosts ,Main_lblOpsCost ,Main_lblSubTotal ,Main_TicketCount ,Main_lblTicketSalesPos ,Main_lblPossibleDollars ,Main_lblPossibleTicletCOmm ,Main_lblTax ,Main_lblNet ,AdminScreen_AdminStaff ,AdminScreen_BoxOffStaff ,AdminScreen_TicketTakers ,AdminScreen_TrafficControl ,AdminScreen_OfficeCosts ,AdminScreen_OfficeEquipment ,AdminScreen_Postage ,AdminScreen_Phones ,AdminScreen_LegalAccountant ,AdminScreen_RentPower ,AdminScreen_Insurance ,AdminScreen_Permits ,AdminScreen_ASCAP ,AdminScreen_Ticketprinting ,MarketingScreen_PublicRelations ,MarketingScreen_CreativePrinting ,MarketingScreen_MktgStaff ,OperationsScreen_SiteOpsCoordinator ,OperationsScreen_Laborers ,OperationsScreen_VenueCost ,OperationsScreen_LandRestore ,OperationsScreen_Kamode ,OperationsScreen_WaterTrucks ,OperationsScreen_EquipmentRent ,OperationsScreen_Petroleum ,OperationsScreen_PowerGenerator ,OperationsScreen_PerimeterLights ,OperationsScreen_Fence ,OperationsScreen_OpsVehicles ,OperationsScreen_ShuttleBuses ,OperationsScreen_MotorHomes ,OperationsScreen_LandPrep ,ProductionScreen_Talent ,ProductionScreen_Sound ,ProductionScreen_Lights ,ProductionScreen_Catering ,ProductionScreen_Stage ,ProductionScreen_LightTowers ,ProductionScreen_Aerials ,SecurityScreen_SecStaff ,SecurityScreen_Vehicles ,SecurityScreen_FirstAid ,SecurityScreen_Communications ,SecurityScreen_Ids ,StaffScreen_ProdStaff ,StaffScreen_StageHands ,TicketComm ,ProductionName,ProductionID FROM Productions WHERE ProductionID = ?
    bool SelectProdctionByID(ProtoolsStandard *pto, ComResponse *resp);

    // SELECT ArtistName from ARTISTS WHERE ProductionID = ?
    bool SelectArtistByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // SELECT Main_lblSize ,Main_lblVenues ,Main_lblArtists ,Main_lblPerformaceDates ,Main_lblProdCost ,Main_lblStaffCost ,Main_lblAdminCosts ,Main_lblMktgCosts ,Main_lblSecCosts ,Main_lblOpsCost ,Main_lblSubTotal ,Main_TicketCount ,Main_lblTicketSalesPos ,Main_lblPossibleDollars ,Main_lblPossibleTicletCOmm ,Main_lblTax ,Main_lblNet ,AdminScreen_AdminStaff ,AdminScreen_BoxOffStaff ,AdminScreen_TicketTakers ,AdminScreen_TrafficControl ,AdminScreen_OfficeCosts ,AdminScreen_OfficeEquipment ,AdminScreen_Postage ,AdminScreen_Phones ,AdminScreen_LegalAccountant ,AdminScreen_RentPower ,AdminScreen_Insurance ,AdminScreen_Permits ,AdminScreen_ASCAP ,AdminScreen_Ticketprinting ,MarketingScreen_PublicRelations ,MarketingScreen_CreativePrinting ,MarketingScreen_MktgStaff ,OperationsScreen_SiteOpsCoordinator ,OperationsScreen_Laborers ,OperationsScreen_VenueCost ,OperationsScreen_LandRestore ,OperationsScreen_Kamode ,OperationsScreen_WaterTrucks ,OperationsScreen_EquipmentRent ,OperationsScreen_Petroleum ,OperationsScreen_PowerGenerator ,OperationsScreen_PerimeterLights ,OperationsScreen_Fence ,OperationsScreen_OpsVehicles ,OperationsScreen_ShuttleBuses ,OperationsScreen_MotorHomes ,OperationsScreen_LandPrep ,ProductionScreen_Talent ,ProductionScreen_Sound ,ProductionScreen_Lights ,ProductionScreen_Catering ,ProductionScreen_Stage ,ProductionScreen_LightTowers ,ProductionScreen_Aerials ,SecurityScreen_SecStaff ,SecurityScreen_Vehicles ,SecurityScreen_FirstAid ,SecurityScreen_Communications ,SecurityScreen_Ids ,StaffScreen_ProdStaff ,StaffScreen_StageHands ,TicketComm ,ProductionName,ProductionID FROM Productions
    bool SelectAllProductions(ComResponse *resp);

    // INSERT INTO Venues (Production_ProductionID, VenueName,VenueAddress1,VenueAddress2,VenueAddress3,VenueCity,VenueState,VenuePostalCode,VenueSpecialNotes) values (?, ?,?,?,?,?,?,?,?)
    bool InsertVenue(ProtoolsStandard *pto, ComResponse *resp);

    // INSERT INTO Tickets (Cost, NumberAvailable, Production_ProductionID, TierDescription, TierName) values (?,?,?,?,?)
    bool InsertTicket(ProtoolsStandard *pto, ComResponse *resp);

    // INSERT INTO TAXES (TaxName, TaxRate, Production_ProductionID) VALUES (?, ?, ?)
    bool InsertTax(ProtoolsStandard *pto, ComResponse *resp);

    // DELETE from ARTISTS where Production_ProductionID = ?
    bool DeleteArtistByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // DELETE FROM Productions where ProductionID = ?
    bool DeleteProductionByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // Delete from Taxes where Production_ProductionID = ?
    bool DeleteTaxByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // Delete from Tickets where Production_ProductionID = ?
    bool DeleteTicketByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // Delete from Venues where Production_ProductionID = ?
    bool DeleteVenueByProductionID(ProtoolsStandard *pto, ComResponse *resp);

    // INSERT INTO Artists (ArtistName, Productions_ProductionID) VALUES (?, ?);
    bool InsertArtists(ProtoolsStandard *pto, ComResponse *resp);

    // INSERT INTO Productions (Main_lblSize ,Main_lblVenues ,Main_lblArtists ,Main_lblPerformaceDates ,Main_lblProdCost ,Main_lblStaffCost ,Main_lblAdminCosts ,Main_lblMktgCosts ,Main_lblSecCosts ,Main_lblOpsCost ,Main_lblSubTotal ,Main_TicketCount ,Main_lblTicketSalesPos ,Main_lblPossibleDollars ,Main_lblPossibleTicletCOmm ,Main_lblTax ,Main_lblNet ,AdminScreen_AdminStaff ,AdminScreen_BoxOffStaff ,AdminScreen_TicketTakers ,AdminScreen_TrafficControl ,AdminScreen_OfficeCosts ,AdminScreen_OfficeEquipment ,AdminScreen_Postage ,AdminScreen_Phones ,AdminScreen_LegalAccountant ,AdminScreen_RentPower ,AdminScreen_Insurance ,AdminScreen_Permits ,AdminScreen_ASCAP ,AdminScreen_Ticketprinting ,MarketingScreen_PublicRelations ,MarketingScreen_CreativePrinting ,MarketingScreen_MktgStaff ,OperationsScreen_SiteOpsCoordinator ,OperationsScreen_Laborers ,OperationsScreen_VenueCost ,OperationsScreen_LandRestore ,OperationsScreen_Kamode ,OperationsScreen_WaterTrucks ,OperationsScreen_EquipmentRent ,OperationsScreen_Petroleum ,OperationsScreen_PowerGenerator ,OperationsScreen_PerimeterLights ,OperationsScreen_Fence ,OperationsScreen_OpsVehicles ,OperationsScreen_ShuttleBuses ,OperationsScreen_MotorHomes ,OperationsScreen_LandPrep ,ProductionScreen_Talent ,ProductionScreen_Sound ,ProductionScreen_Lights ,ProductionScreen_Catering ,ProductionScreen_Stage ,ProductionScreen_LightTowers ,ProductionScreen_Aerials ,SecurityScreen_SecStaff ,SecurityScreen_Vehicles ,SecurityScreen_FirstAid ,SecurityScreen_Communications ,SecurityScreen_Ids ,StaffScreen_ProdStaff ,StaffScreen_StageHands ,TicketComm ,ProductionName)values(? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,?)
    bool InsertProduction(ProtoolsStandard *pto, ComResponse *resp);

    // This is going to select the username.
    bool AuthUserByUserName(const QString &usernmae, QString userpassword);

    QList<User *> *Users;

    QList<ProtoolsStandard *> *PTList;

    void GetAllUsers();

    bool GetUserByUserID(int userID, User *u);

    bool InsertUser(User *u);

    bool UpdateUser(User *u);

    bool DeleteUser(User *u);

private:

    // This is the settings file.
    CSSettingsInformation *sd;

};

#endif // DATABASEFACADE_H
